package com.yenlien.traceyun.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.service.rest.control.ModelClassifyRestService;
import com.yenlien.traceyun.webase.controller.BaseController;
import com.yenlien.traceyun.webase.exception.BusinessException;
import com.yenlien.traceyun.webase.utils.CheckParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * Created by LiuSha on 2020/3/24.
 * 模型库分类
 */
@RestController
@RequestMapping(value = "/model/classify")
public class ModelClassifyController extends BaseController {
    @Autowired
    private ModelClassifyRestService modelClassifyService;
    @Value("${traceyun.app.id}")
    private String appId;

    //一级分类
    @RequestMapping(value = "/findByOne", method = RequestMethod.POST)
    public Object findByOne(@RequestBody JSONObject param) {
        CheckParams.checkJson(param, new String[]{"userType", "companyId"});
        param.put("appId", appId);
        return modelClassifyService.findByOne(param);
    }

    //下级分类
    @RequestMapping(value = "/findByParentId/{parentId}", method = RequestMethod.GET)
    public Object findByParentId(@PathVariable String parentId) throws BusinessException {
        return modelClassifyService.findByParentId(parentId);
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable String id) {
        return modelClassifyService.findById(id);
    }

}
